package 力扣日常刷题.木22二月.第15天221;

import 力扣日常刷题.ListNode;

import java.util.List;

/**
 * @author 帅小伙
 * @date 2022/2/21
 * @description
 */
public class Demo115删除链表倒数第N个节点 {

    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(0,head);
        ListNode first = head;
        ListNode second = dummy;
        for (int i = 0; i < n; i++) first = first.next;
        while(first != null){
            first = first.next;
            second = second.next;
        }
        second.next = second.next.next;
        return dummy.next;
    }

}
